<template>
    <div>
        <el-dialog v-model="ViewdialogVisible" width="80%" align-center destroy-on-close draggable>
            <template #header="{ close }">
                <div class="dialog-header flex justify-between items-center">
                    <div>获奖审核</div>
                    <el-icon class="el-icon--left cursor-pointer" @click="close">
                        <CircleCloseFilled color="#fff" />
                    </el-icon>
                </div>
            </template>
            <div class="pb-[150px]">
                <!-- 基本信息 -->
                <div class="bg-white mt-[10px]">
                    <BaseHead>基本信息</BaseHead>
                    <div class="p-[10px]">
                        <el-descriptions title="" :column="2" border label-width="140">
                            <el-descriptions-item label-class-name="gdlable" label="奖励批准号">{{
            ruleForm.honorSn
        }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="获奖类型">{{
                ruleForm.honorNumber == 1 ? '成果奖' : "人才奖"
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="奖励名称">{{
                ruleForm.name
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="成果名称">{{
                ruleForm.productName
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="发证机关">{{
                ruleForm.honorUnit
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="获奖级别">{{
                formatHonorLevelId(ruleForm.honorLevelId)
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="获奖等级">{{
                formatHonorGradeId(ruleForm.honorGradeId)
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="奖励类别">{{
                formatHonorTypeId(ruleForm.honorTypeId)
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="获奖日期">{{
                ruleForm.honorDate.slice(0, 10)
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="成果形式">{{
                ruleForm.productMode
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="总参加单位数">{{
                ruleForm.totalUnitNum
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="所属单位">{{
                formatUnitId(ruleForm.unitId)
            }}</el-descriptions-item>
                        </el-descriptions>
                    </div>
                </div>
                <!-- 详细信息 -->
                <div class="bg-white mt-[10px]">
                    <BaseHead>详细信息</BaseHead>
                    <div class="p-[10px]">
                        <el-descriptions title="" :column="2" border label-width="140">
                            <el-descriptions-item label-class-name="gdlable" label="合作类型">{{
            ruleForm.cooperationType == 1 ? '独立申请' : "联合申请"
        }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="获奖金额">{{
                ruleForm.honorFee
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="本校奖金比例"
                                v-if="ruleForm.cooperationType == 2">{{
            ruleForm.schoolScale
        }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="完成单位">{{
                ruleForm.completeUnit
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="单位排名">{{
                ruleForm.unitOrderId
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="学科门类">{{
                ruleForm.subjectClassId == 2 ? '科技类' : "社科类"
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="学科分类">{{
                formatSubjectId(ruleForm.subjectId)
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="项目来源">{{
                formatProjectSourceId(ruleForm.projectSourceId)
            }}</el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="奖励证书">
                                <div v-for="item in ruleForm.fileList" :key="item.id">{{ item.fileName
                                    }}<el-link type="primary" style="margin-left: 8px;"
                                        @click="downloadMet(item.id)">下载</el-link>
                                </div>
                            </el-descriptions-item>
                            <el-descriptions-item label-class-name="gdlable" label="备注">{{
                                ruleForm.note
                                }}</el-descriptions-item>
                        </el-descriptions>
                    </div>
                </div>
                <!-- 完成人信息 -->
                <div class="bg-white mt-[10px]">
                    <BaseHead>完成人信息 </BaseHead>
                    <div class="p-[10px]">
                        <el-table :data="tableData" border style="width: 100%">
                            <el-table-column align="center" type="index" label="署名顺序" width="80" />
                            <el-table-column align="center" prop="authorType" label="完成人类型">
                                <template #default="scope">
                                    {{
                                    scope.row.authorType=='1'?'教师': scope.row.authorType=='2'?'学生':'校外'
                                    }}</template>
                            </el-table-column>
                            <el-table-column align="center" prop="authorName" label="完成人姓名">

                            </el-table-column>
                            <el-table-column align="center" prop="eduLevelId" label="学历">
                                <template #default="scope">
                                    {{
                                    formateduLevelId(scope.row.eduLevelId)
                                    }}</template>
                            </el-table-column>
                            <el-table-column align="center" prop="authorUnit" label="工作单位">
                                <template #default="scope">
                                    <span v-if="scope.row.authorType == 3">{{scope.row.authorUnit }}</span>
                                    <Feedback v-else :id="scope.row.authorUnitId" :list="sydwList"
                                        :mapping="['codeColumn', 'valueColumn']">
                                    </Feedback>
                                </template>
                            </el-table-column>
                            <el-table-column align="center" prop="titleId" label="职称">
                                <template #default="scope">
                                    <el-tree-select v-model="scope.row.titleId" node-key="id" :data="zcList"
                                        :render-after-expand="false" disabled />
                                </template>
                            </el-table-column>
                            <el-table-column align="center" prop="workRatio" label="贡献率（%）">
                            </el-table-column>
                        </el-table>
                    </div>
                </div>
            </div>
            <!-- <Checkcomponents :procInsId="procInsId" @success="refresh" class="mt-[10px]" /> -->
            <template #footer>
                <div class="dialog-footer">
                    <Checkcomponents :procInsId="procInsId" class="mt-[10px]" @success="refresh" />
                </div>
            </template>
        </el-dialog>
    </div>
</template>
<script setup>
import BaseHead from "@/views/project/components/BaseHead.vue";
import Checkcomponents from "@/views/flowable/processInstance/detail/components.vue";

const ViewdialogVisible = defineModel();
const props = defineProps({
    hjjbList: Array,
    hjdjList: Array,
    hjnbList: Array,
    ssdwList: Array,
    xmlyList: Array,
    xlList: Array,
    zcList: Array,
    zcgsdwList: Array,
    kjxkflList: Array,
    skxkflList: Array,
    sydwList: Array,
})


const procInsId = ref(null); //流程实例id


const ruleForm = reactive({
    honorSn: "",
    honorNumber: 1,
    name: "",
    productName: "",
    honorUnit: "",
    honorLevelId: "",
    honorGradeId: "",
    honorTypeId: "",
    honorDate: "",
    productMode: "",
    totalUnitNum: "",
    unitId: "",
    cooperationType: "1",
    honorFee: "",
    schoolScale: '',
    completeUnit: "",
    unitOrderId: "",
    subjectClassId: "1",
    subjectId: "",
    projectSourceId: "",
    note: "",
});
const tableData = reactive([
]);

const formatHonorLevelId = (cellValue) => {
    if (props.hjjbList.length && cellValue) {
        return props.hjjbList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}
const formatHonorGradeId = (cellValue) => {
    if (props.hjdjList.length && cellValue) {
        return props.hjdjList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}
const formatHonorTypeId = (cellValue) => {
    if (props.hjnbList.length && cellValue) {
        return props.hjnbList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}

const formatUnitId = (cellValue) => {
    if (props.zcgsdwList.length && cellValue) {
        return props.zcgsdwList.find(item => item.codeColumn == cellValue).valueColumn
    } else {
        return ''
    }


}

const formatProjectSourceId = (cellValue) => {
    if (props.xmlyList.length && cellValue) {
        if (props.xmlyList.find(item => item.id == cellValue)) {
            return props.xmlyList.find(item => item.id == cellValue).label
        } else {
            return ''
        }

    } else {
        return ''
    }


}

const formatSubjectId = (cellValue) => {
    if (ruleForm.subjectClassId == 2) {
        if (props.kjxkflList.length && cellValue) {
            return props.kjxkflList.find(item => item.id == cellValue) ? props.kjxkflList.find(item => item.id == cellValue).label : ''
        } else {
            return ''
        }
    } else {
        if (props.skxkflList.length && cellValue) {
            return props.skxkflList.find(item => item.id == cellValue) ? props.skxkflList.find(item => item.id == cellValue).label : ''
        } else {
            return ''
        }
    }


}
const formateduLevelId = (cellValue) => {
    if (props.xlList.length && cellValue) {
        return props.xlList.find(item => item.code == cellValue).name
    } else {
        return ''
    }


}

const getRuleForm = (i, processId) => {
    if (i.honorAuthorVOs && i.honorAuthorVOs.length > 0) {
        tableData.length = 0; // 清空数组
        tableData.push(...i.honorAuthorVOs); // 添加新元素

    }
    for (const key in i) {
        ruleForm[key] = i[key];
    }
    procInsId.value = processId
}
const { proxy } = getCurrentInstance();
const downloadMet = (i) => {
    proxy.$download.common(i)
}

const emit = defineEmits(['callBack']);
const refresh = () => {
    ViewdialogVisible.value = false
    emit('callBack', "")
}

defineExpose({
    getRuleForm
})
</script>
<style lang="scss">
.gdlable {
    width: 140px;
}
</style>
<style scoped lang="scss">
@import url("@/views/achievement/index.scss");

:deep(.el-select--default) {


    .el-select__wrapper.is-disabled {
        background-color: #fff;
        box-shadow: 0 0 0 0px var(--el-select-disabled-border) inset;
        color: #606266;
        cursor: not-allowed;

        .el-select__selected-item {
            color: #606266;
        }
    }

    .el-select__suffix {
        display: none;
    }
}
</style>
